#coding=utf8
import urllib2
import re
def getname(content):
    namere = re.compile("<title>(.*?)</title>")
    t = namere.findall(content)

def getchapter(url,name="unamed",mylog=None):
    "parser html source to generate chapterlist"
    myre = re.compile("<a target=_blank href = '(\d+?)'>(.*?)</a>")
    
    chapterlist = []
    content = ''
    try:
        content = urllib2.urlopen(url).read()
        if content:
            for item in myre.findall(content):
                chapterlist.append([urllib2.urlparse.urljoin(url, item[0]), 
                                    item[1].decode('gbk').encode('utf-8')])
        return chapterlist
    except  Exception, e:
        if mylog:
            mylog.writeLog(str(e)+'in getchapter','error')
        else:
            print e
        return None

if __name__ == '__main__':
    for i in getchapter('http://www.89890.com/Comic/2490/'):
        print i[0], i[1]
